<template>
  <span>
    <el-button type="primary" title="导出全部" size="small" @click="exportAll"  v-loading.fullscreen.lock="fullscreenLoading">导出<i class="el-icon-upload2 el-icon--right"></i></el-button>
    <el-button type="primary" v-if="hasPagination" size="small" title="导出当前页" @click="exportCurrent" v-loading.fullscreen.lock="fullscreenLoading" >导出当前页<i class="el-icon-upload2 el-icon--right"></i></el-button>
  </span>
</template>
<script>
  // exportExc: {
  //   hasPagination: true,
  //   headers: [],
  //   fileName: '日志管理',
  //   dataFunc: function() {
  //   },
  //   params: [],
  //   dataFunc2: function() {
  //   },
  //   params2: []
  // }

import Excel from 'utils/exportExcel.js'
export default {
  name: 'ExportExcel',
  props: {
    /**
     * 是否是分页的导出
     */
    hasPagination: {
      type: Boolean,
      default() {
        return false
      }
    },
    headers: {
      type: Array,
      default() {
        return []
      }
    },
    fileName:{
      type:String,
      default(){
        return '导出的Excel文件.xlsx'
      }
    },
    dataFunc:{
      type:Function,
      default(){
        return function(){}
      }
    },
    params:{
      type:Array,
      default(){
        return []
      }
    },
    dataFunc2:{
      type:Function,
      default(){
        return function(){}
      }
    },
    params2:{
      type:Array,
      default(){
        return []
      }
    }
  },
  data() {
    return {
      datas:[],
      fullscreenLoading: false
    }
  },
  methods: {
      exportAll(){
        const self = this
        self.fullscreenLoading = true
        Excel.exportAll(self).then((success) => {
          self.fullscreenLoading = false
        })
        .catch((err) => {
           self.fullscreenLoading = false
        })
        console.log('excel:exportAll');
      },
      exportCurrent(){
        const self = this
        self.fullscreenLoading = true
        Excel.exportCurrent(self).then((success) => {
           self.fullscreenLoading = false
        })
        .catch((err) => {
           self.fullscreenLoading = false
        })
        console.log('excel:exportCurrent');
      }
  }
}
</script>
